@extends('admin.layout.layout', ['row' => @$page])

@section('contain')

    <style>
        .table .tth{
            background-color: rgba(0, 0, 0, 0.05);
            width: 150px;
            font-weight: bold;
        }
        .table .ttd{
            width: 350px;
        }
        .table .ttt{
            padding: 0;
        }
        .ttt .table{
            margin: 0;
        }
        .ttt .table img + p{
            text-align: center;
            margin: 10px 0 0;
        }
        .tst{
            color: #00b050;
            font-weight: 700;
            text-align: center;
            font-size: 1.25rem;
        }
    </style>

    <div class="portlet">
        <div class="portlet-title">
            <div class="caption">
                <x-portlet-breadcrumb :page="$page"></x-portlet-breadcrumb>
            </div>
            <div class="actions"></div>
        </div>
        {{--<x-upload-box name="sfasdf"></x-upload-box>--}}
        <form action="/{{ request()->path() }}/../" method="post" onsubmit="return checkVal(this)" class="warranty-form t-right">
            @csrf
            @method('PUT')
            <input type="text" name="_previous_" value="{{ request()->header('referer') }}" hidden>
            <x-warranty-message :warranty="$data"></x-warranty-message>

            <table class="table s3">
                <tbody>
                <tr>
                    <td class="tth">{{ ts('warrantyid') }}</td>
                    <td class="ttd bg-light">{{ $data->warranty_id }}</td>
                    {{--<td class="tth">{{ ts('azfs') }}</td>
                    <td class="ttd bg-light">{{ $data->pre_id ? ts('TCAZ') : ts('ptaz') }}</td>--}}
                    <td colspan="4"></td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('CUSTOMER') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('CUSTOMERNAME') }}</td>
                    <td class="ttd">
                        <input type="text" name="first_name" value="{{ $data->first_name ?: old('first_name') }}" class="form-control">
                    </td>
                    <td class="tth">{{ ts('phonenumber') }}</td>
                    <td class="ttd">
                        <div class=" input-group custom-control-inline">
                            <div class="input-group-prepend">
                                <select name="extension" class="form-control">
                                    @foreach(\App\Models\PhoneExtension::get(['id', 'phone_ext']) as $v)
                                        <option value="{{ $v->phone_ext }}" {{ ($data->extension == $v->phone_ext || old('phone_number')==$v->phone_ext ) ? 'selected' : '' }}>{{ $v->phone_ext }}</option>
                                    @endforeach
                                </select>
                            </div>
                            <input type="number" name="phone_number" value="{{ $data->phone_number ?: old('phone_number') }}" class="form-control">
                        </div>
                    </td>
                    <td class="tth">{{ ts('email') }}</td>
                    <td class="ttd">
                        <input type="email" name="email_address" value="{{ $data->email_address ?: old('email_address') }}" class="form-control">
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('region') }}</td>
                    <td>
                        <select name="region_id" id="" class="form-control region_json" data-value="{{ $data->region_id ?: old('region_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->region_id }}" selected>{{ ts('region_master.'.$data->region_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('province') }}</td>
                    <td>
                        <select name="province_id" id="" class="form-control province_json" data-value="{{ $data->province_id ?: old('province_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->province_id }}" selected>{{ ts('province_master.'.$data->province_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('city') }}</td>
                    <td>
                        <select name="city" id="" class="form-control city_json" data-value="{{ $data->city ?: old('city') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->city }}" selected>{{ ts('cities.'.$data->city) }}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('addresss') }}</td>
                    <td colspan="3">
                        <input type="text" name="address" value="{{ $data->address ?: old('address') }}" class="form-control">
                    </td>
                    <td class="tth">{{ ts('zip') }}</td>
                    <td>
                        <input type="text" name="addresss" value="{{ $data->zip ?: old('zip') }}" class="form-control">
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLEINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('year') }}</td>
                    <td>
                        <select name="year_id" id="" class="form-control make_json_year" data-value="{{ $data->year_id ?: old('year_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->year_id }}" selected>{{ $data->year_id }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('make') }}</td>
                    <td>
                        <select name="make_id" id="" class="form-control make_json_make" data-value="{{ $data->make_id ?: old('make_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->make_id }}" selected>{{ ts('make_master.'.$data->make_id) }}</option>
                        </select>
                    </td>
                    <td class="tth">{{ ts('model') }}</td>
                    <td>
                        <select name="model_id" id="" class="form-control make_json_model" data-value="{{ $data->model_id ?: old('model_id') }}">
                            <option value="">{{ ts('select') }}</option>
                            <option value="{{ $data->model_id }}" selected>{{ ts('model_master.'.$data->model_id) }}</option>
                        </select>
                        {{--<input type="text" name="model_id" value="{{ $data->model_id ?: old('model_id') }}" class="form-control" >--}}
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('licenseplate') }}</td>
                    <td>
                        <input type="text" name="license_plate" value="{{ $data->license_plate ?: old('license_plate') }}" class="form-control" >
                    </td>
                    <td class="tth">{{ ts('vinnumber') }}</td>
                    <td colspan="3">
                        <input type="text" name="vin_number" value="{{ $data->vin_number ?: old('vin_number') }}" class="form-control" >
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONINFORMATION') }}</td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('distributor') }}</td>
                    <td>
                        <input type="text" class="form-control sdjc" disabled name="sdjc" value="{{ getDJc($data->user_id) }}">
                    </td>
                    <td class="tth">{{ ts('qudao') }}</td>
                    <td>
                        <div class="input-group">
                            <input type="number" value="{{ $data->user_id }}" name="user_id" hidden>
                            <select class="form-control roll_user_id" name="user_id" disabled>
                                <option value="{{ $data->user_id }}">{{ getJc($data->user_id) }}</option>
                            </select>
                            @empty($data->pre_id)
                                <div class="input-group-prepend">
                                    <span class="btn btn-primary"  data-toggle="modal" data-target="#changeWarrantyUser">{{ ts('XG') }}</span>
                                </div>
                            @endif
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="tth">{{ ts('INSTALLERNAME') }}</td>
                    <td>
                        <input type="text" name="installer_name" value="{{ $data->installer_name ?: old('installer_name') }}" class="form-control" >
                    </td>
                    <td class="tth">{{ ts('INSTALLATIONDATE') }}</td>
                    <td>
                        <div class="input-group">
                            <input type="text" name="installation_date" value="{{ $data->installation_date ?: old('installation_date') }}" class="form-control flatpickr-ymdhis" data-max="{{ date('Y-m-d H:i:s') }}">
                            <div class="input-group-prepend">
                                <span class="btn btn-primary fkr-clear"><i class="fa fa-times"></i></span>
                            </div>
                        </div>
                    </td>
                    <td class="tth">{{ ts('INSTALLERPRICE') }}</td>
                    <td>
                        <input type="text" name="installation_price" value="{{ $data->installation_price ?: old('installation_price') }}" class="form-control" >
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('INSTALLATIONPICTURE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt">
                        @include('admin.components.aztp-tb')
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('VEHICLECOVERAGE') }}</td>
                </tr>
                <tr>
                    <td colspan="6" class="ttt">
                        <div class="container-fluid">
                            @include('admin.subview.warranty_coverage', ['coverages' => $data->warranty_to_vehicle_coverage, 'is_precut' => @$data->pre_id])
                        </div>
                    </td>
                </tr>
                <tr>
                    <td colspan="6" class="tst">{{ ts('BCSM') }}</td>
                </tr>
                <tr>
                    <td colspan="6" height="auto">
                        <textarea name="additional_comments"  height="auto" rows="6" id="" class="form-control">{{ @$data->additional_comments ?: old('additional_comments') }}</textarea>
                    </td>
                </tr>
                </tbody>
            </table>

            <div class="mt-4">
                <button class="btn btn-primary">{{ ts('store') }}</button>
            </div>
        </form>
        @php
            $wUser = getUser($data->user_id);
            $wDealers = [];
            $Dealers = [];
            $wDTId = 0;
            if (empty($wUser->id)) {
            } else {
                if ($wUser->user_type==2) {
                    $Dealers = getDealers($wUser->id);
                    $wDealers[] = $wUser;
                    $wDTId = $wUser->id;
                }
                if ($wUser->user_type==3) {
                    $Dealers = getDealers($wUser->creator_id);
                    $wDealers[] = getUser($wUser->creator_id);
                    $wDTId = $wUser->creator_id;
                }
                foreach ($Dealers as $v) {
                    $wDealers[] = $v;
                }
            }
        @endphp
        <div class="modal fade modal-s1" id="changeWarrantyUser">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title font-green">{{ ts('xgqd') }}</h5>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        @if(session('admin.user_type')==1)
                            <div class="form-item">
                                <div class="form-label" required="">{{ ts('xzsd') }}</div>
                                <div class="form-input">
                                    <select class="form-control" name="distributor_id">
                                        @if(session('admin.user_type')==1)
                                            @foreach(getDistributors() as $v)
                                                <option value="{{ $v->id }}" {{ $wDTId == $v->id ? 'selected' : '' }}>{{ $v->abbr ?: $v->company_name }}</option>
                                            @endforeach
                                        @endif
                                    </select>
                                </div>
                            </div>
                        @endif

                        <div class="form-item">
                            <div class="form-label" required="">{{ ts('xzjxs') }}</div>
                            <div class="form-input">
                                <select class="form-control" name="dealer_id" placeholder="">
                                    @foreach($wDealers as $v)
                                        <option value="{{ $v->id }}" {{ $data->user_id == $v->id ? 'selected' : '' }}>{{ $v->abbr ?: $v->company_name }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="py-3 text-center">
                            <button type="button" class="btn btn-primary" onclick="handleChangeWarrantyUser()">{{ ts('confirm') }}</button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection